<?php

class Controller {
	
	protected $_controller;
	protected $_action;
	protected $_template;
        protected $_auto_render;
        protected $_render_header;

	function __construct($controller, $action) {
		global $session;
		
		$this->_auto_render = true;
                $this->_render_header = true;
		
		$model = ucfirst($controller."Model");//ucfirst($inflect->singularize($controller));
		
		$this->_controller = ucfirst($controller);
		$this->$model = new $model;
		$this->_action = $action;
		$this->_template = new Template($controller, $action);
		$this->session = $session;
	}

	function set($name, $value) {
            $this->_template->set($name, $value);
	}

	function __destruct() {
		if ($this->_auto_render) {
                    $this->_template->render($this->_render_header);
                }
	}
	
	function render() {
            $this->_template->render($this->_render_header);
        }

        function redirect($url) {
            //header("Location: $url");
            header("Location:".$url);
        }
}